package com.student.Activitys.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.student.Activitys.R;
import com.student.Activitys.adapter.base.BaseRefreshAdapter;
import com.student.Activitys.adapter.viewholder.FooterViewHolder;
import com.student.Activitys.adapter.viewholder.SupportMyApplyViewHolder;
import com.student.Activitys.bean.SupportMyApplyBean;
import com.student.Activitys.utils.Constant;

import java.util.List;

/**
 * 项目名称：智慧校园学生端
 * 类描述：我的奖学金申请 适配器
 * 创建人：张飞祥
 * 创建时间：2017/10/25 14:47
 * 修改人：张飞祥
 * 修改时间：2017/10/25 14:47
 * 修改备注：
 */
public class SupportMyApplyAdapter extends BaseRefreshAdapter {

    private List<SupportMyApplyBean> list;  //数据源
    private Context context;                //上下文
    private int mLoadMoreStatus = 0;        //上拉加载更多状态-默认为0
    private String status = "";             //状态名称
    private Drawable statusDrawable = null; //状态View

    public SupportMyApplyAdapter(Context context,List<SupportMyApplyBean> list) {
        super(context, list);
        this.list = list;
        this.context = context;
    }


    @Override
    protected int getLayoutItmeResId() {
        return R.layout.item_support_my_apply;
    }

    @Override
    protected int getLayoutFootResId() {
        return R.layout.layout_load_footview;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof SupportMyApplyViewHolder) {
            SupportMyApplyViewHolder viewHolder = (SupportMyApplyViewHolder) holder;
            //将数据保存在itemView的Tag中，以便点击时进行获取
            viewHolder.itemView.setTag(position);
            /**
             * 显示 UI 逻辑判断
             */
            switch (list.get(position).getApplyState()){
                case Constant.SUPPORT_MY_WAIT:         //待审核
                    //设置 文字左侧 图片 "灰色"
                    Drawable drawable = context.getResources().getDrawable(R.drawable.ic_text_gray_left);
                    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                    viewHolder.tvItemMyApplyName.setCompoundDrawables(drawable, null, null, null);
                    //设置状态名称
                    status = "待审核";
                    //设置状态图片
                    statusDrawable = context.getResources().getDrawable(R.drawable.ic_state_wait);
                    statusDrawable.setBounds(0, 0, statusDrawable.getIntrinsicWidth(), statusDrawable.getIntrinsicHeight());
                    break;
                case  Constant.SUPPORT_MY_COLLEGE_NO:  //学院拒绝
                    //设置状态名称
                    status = "学院拒绝";
                    //设置状态图片
                    statusDrawable = context.getResources().getDrawable(R.drawable.ic_state_no);
                    statusDrawable.setBounds(0, 0, statusDrawable.getIntrinsicWidth(), statusDrawable.getIntrinsicHeight());
                    break;
                case  Constant.SUPPORT_MY_COLLEGE_YES:  //学院通过
                    //设置状态名称
                    status = "学院通过";
                    //设置状态图片
                    statusDrawable = context.getResources().getDrawable(R.drawable.ic_state_yes);
                    statusDrawable.setBounds(0, 0, statusDrawable.getIntrinsicWidth(), statusDrawable.getIntrinsicHeight());
                    break;
                case  Constant.SUPPORT_MY_SCHOOL_NO:    //学校拒绝
                    //设置状态名称
                    status = "学校拒绝";
                    //设置状态图片
                    statusDrawable = context.getResources().getDrawable(R.drawable.ic_state_no);
                    statusDrawable.setBounds(0, 0, statusDrawable.getIntrinsicWidth(), statusDrawable.getIntrinsicHeight());
                    break;
                case  Constant.SUPPORT_MY_SCHOOL_YUS:    //学校通过
                    //设置状态名称
                    status = "学校通过";
                    //设置状态图片
                    statusDrawable = context.getResources().getDrawable(R.drawable.ic_state_yes);
                    statusDrawable.setBounds(0, 0, statusDrawable.getIntrinsicWidth(), statusDrawable.getIntrinsicHeight());
                    break;
            }

            //设置标题文字
            viewHolder.tvItemMyApplyName.setText(list.get(position).getTitle());
            //设置状态文字
            viewHolder.tvItemMyApplyState.setText(status);
            //设置状态图片
            viewHolder.tvItemMyApplyState.setCompoundDrawables(null, null,statusDrawable, null);

        } else if (holder instanceof FooterViewHolder) {
            FooterViewHolder footViewHolder = (FooterViewHolder) holder;
            switch (mLoadMoreStatus) {
                case Constant.PULLUP_LOAD_MORE:
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("上拉加载更多");
                    break;
                case Constant.LOADING_MORE:
                    footViewHolder.pbLoad.setVisibility(View.VISIBLE);
                    footViewHolder.tvLoadText.setText("正加载更多...");
                    break;
                case Constant.NO_LOAD_MORE:
                    //隐藏加载更多
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("没有更多数据可加载了...");
                    break;
            }
        }
    }

    @Override
    public void changeMoreStatus(int status) {
        mLoadMoreStatus = status;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new SupportMyApplyViewHolder(view);
    }
}
